﻿#region Intro and note
/*
Copyright © 2009, Hoang Trung - YkhoaNet
All rights reserved.
http://ykhoa.net, http://www.htmedsoft.com/

Note: Class này thể hiện các thuộc tính và hành vi của toa thuốc tại lớp BLL.
-	090527 Thịnh thay cấu trúc đa tầng vào phần save toa thuốc về DB

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

- Neither Hoang Trung - YkhoaNet, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior written 
permission. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.


*/
#endregion
using System;

	/// <summary>
	/// Summary description for CToathuoc.
	/// </summary>
public class CToathuoc
{
    #region local variable declaring
    private int _nErrorCode = -1;//that mean OK;

    string _sMaphieu;
    string _sMaPhieuKham_Cu;

    int _nDoiTuong = 1;
    bool _bCheckBaoHiem = true;
    const char SEPERATE_SYMBOL = '|';

    //use in tach toa thuoc theo khoa
    string _dbname_Static;
    string _sLoaiKham;

    int _nThuocID;
    string _sDbName;
    //string _sTenThuoc;
    int _nSoLuong;
    string _sDonVi;
    string _sCachDung;
    string _nLanDung;
    string _nLuongDung;
    string _sDonViDung;
    string _sGhiChu;
    //double _dDonGia;

    string _sThuocID_s;
    string _sDbName_s;
    //string _sTenThuoc_s;
    string _sSoLuong_s;
    string _sDonVi_s;
    string _sCachDung_s;
    string _sLanDung_s;
    string _sLuongDung_s;
    string _sDonViDung_s;
    string _sGhiChu_s;
    //string _sDonGia_s;
    #endregion
    private DAL_DonThuoc dal_DonThuoc;
    public CToathuoc(string sMaPhieu, int nDoiTuong, bool bCheckBaoHiem)
    {
        _sMaphieu = sMaPhieu;

        _nDoiTuong = nDoiTuong;
        _bCheckBaoHiem = bCheckBaoHiem;

        _sThuocID_s = "";
        _sDbName_s = "";

        _sSoLuong_s = "";
        _sDonVi_s = "";
        _sCachDung_s = "";
        _sLanDung_s = "";
        _sLuongDung_s = "";
        _sDonViDung_s = "";
        _sGhiChu_s = "";

    }
    #region Properties
    public int ErrorCode { get { return _nErrorCode; } }
    public string MaPhieu
    {
        get { return _sMaphieu; }
        set { _sMaphieu = value; }
    }

    public string MaPhieuKham_Cu
    {

        set { _sMaPhieuKham_Cu = value; }
    }

    public int DoiTuong
    {
        get { return _nDoiTuong; }
        set { _nDoiTuong = value; }
    }

    public bool CheckThuocBaoHiem
    {
        set { _bCheckBaoHiem = value; }
    }

    public string DBName_Static
    {
        set { _dbname_Static = value; }
    }
    public string LoaiKham
    {
        set { _sLoaiKham = value; }
    }



    //thuoc id
    public int ThuocID
    {
        get { return _nThuocID; }
        set
        {
            _nThuocID = value;
            _sThuocID_s += _nThuocID.ToString().Trim() + SEPERATE_SYMBOL;
        }
    }
    //DBName
    public string DBname
    {
        get { return _sDbName; }
        set
        {
            _sDbName = value;
            _sDbName_s += _sDbName.Trim() + SEPERATE_SYMBOL;
        }
    }

    //So luong
    public int SoLuong
    {
        get { return _nSoLuong; }
        set
        {
            _nSoLuong = value;
            _sSoLuong_s += _nSoLuong.ToString().Trim() + SEPERATE_SYMBOL;
        }
    }
    //Don vi
    public string DonVi
    {
        get { return _sDonVi; }
        set
        {
            _sDonVi = value;
            _sDonVi_s += _sDonVi.Trim() + SEPERATE_SYMBOL;
        }
    }
    //Cach dung
    public string CachDung
    {
        get { return _sCachDung; }
        set
        {
            _sCachDung = value;
            _sCachDung_s += _sCachDung.Trim() + SEPERATE_SYMBOL;
        }
    }
    //Lan dung
    public string LanDung
    {
        get { return _nLanDung; }
        set
        {
            _nLanDung = value;
            _sLanDung_s += _nLanDung.ToString().Trim() + SEPERATE_SYMBOL;
        }
    }
    //Luong dung
    public string LuongDung
    {
        get { return _nLuongDung; }
        set
        {
            _nLuongDung = value;
            _sLuongDung_s += _nLuongDung.ToString().Trim() + SEPERATE_SYMBOL;
        }
    }
    //Don vi dung
    public string DonViDung
    {
        get { return _sDonViDung; }
        set
        {
            _sDonViDung = value;
            _sDonViDung_s += _sDonViDung.Trim() + SEPERATE_SYMBOL;
        }
    }
    //Ghi chus
    public string GhiChu
    {
        get { return _sGhiChu; }
        set
        {
            _sGhiChu = value;
            _sGhiChu_s += _sGhiChu.Trim() + SEPERATE_SYMBOL;
        }
    }

    #endregion

    #region Utility
    /// <summary>
    /// Bỏ ký tự phân cách cuối cùng trong chuỗi
    /// </summary>
    private void removeTrail()
    {
        _sThuocID_s = _sThuocID_s.TrimEnd(SEPERATE_SYMBOL);
        _sDbName_s = _sDbName_s.TrimEnd(SEPERATE_SYMBOL);
        //_sTenThuoc_s = _sTenThuoc_s.TrimEnd(SEPERATE_SYMBOL);
        _sSoLuong_s = _sSoLuong_s.TrimEnd(SEPERATE_SYMBOL);
        _sDonVi_s = _sDonVi_s.TrimEnd(SEPERATE_SYMBOL);
        _sCachDung_s = _sCachDung_s.TrimEnd(SEPERATE_SYMBOL);
        _sLanDung_s = _sLanDung_s.TrimEnd(SEPERATE_SYMBOL);
        _sLuongDung_s = _sLuongDung_s.TrimEnd(SEPERATE_SYMBOL);
        _sDonViDung_s = _sDonViDung_s.TrimEnd(SEPERATE_SYMBOL);
        _sGhiChu_s = _sGhiChu_s.TrimEnd(SEPERATE_SYMBOL);
        //_sDonGia_s = _sDonGia_s.TrimEnd(SEPERATE_SYMBOL);
    }


    #endregion


    #region GET

    #endregion
    #region Insert, update, delete
    /// <summary>
    /// Xử lý chuỗi rồi call DAL để thêm toa thuốc về DB
    /// </summary>
    /// <returns></returns>
    public string addNewToaThuoc()
    {
        string sRetVal = "";
        dal_DonThuoc = new DAL_DonThuoc();
        //remove trail SEPERATE_SYMBOL at all the local string variables.
        removeTrail();

        //call the DAL addNewToathuoc and get message return
        sRetVal = Convert.ToString(dal_DonThuoc.addNewToaThuoc_DAL(_sMaPhieuKham_Cu, _sMaphieu, _nDoiTuong, _bCheckBaoHiem, SEPERATE_SYMBOL, _dbname_Static, _sLoaiKham,
            _sThuocID_s, _sDbName_s, _sSoLuong_s, _sDonVi_s,
            _sCachDung_s, _sLanDung_s, _sLuongDung_s, _sDonViDung_s, _sGhiChu_s));

        //get error code return
        _nErrorCode = dal_DonThuoc.ErrorCode_DAL;
        return sRetVal;
    }

    #endregion
}
